package com.gosophia.taskManagement.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

import com.gosophia.commons.DateTranslate;
import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.taskManagement.dto.JobHandleRecordsDTO;
import com.gosophia.taskManagement.dto.MissionDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;

@SuppressWarnings("serial")
public abstract class BaseMissionDetailAction extends BaseSupportAction{
    
    protected Long missionId;
    
    protected MissionDTO missionDTO;
    
    private boolean missionEnded = false;
    
    @Autowired
    protected TaskManagementWebService taskManagementWebService;
    
    public static Map<String, String> content = new HashMap<String, String>();
      
//    private String historyListJsonString ;
    
    private List<JobHandleRecordsDTO> historyList = new ArrayList<JobHandleRecordsDTO>();
    //JOB部分
    public  List<JobHandleRecordsDTO> getHistoryList() {
        try {
            historyList = taskManagementWebService.findJobHandleRecords(missionId);
        } catch (BusinessException e) {
            e.printStackTrace();
        }
        try {
            //将mission创建记录添加到记录列表第一条
            missionDTO = taskManagementWebService.findMissionDetailByMissionId(missionId);
            JobHandleRecordsDTO missionCreateRecord = new JobHandleRecordsDTO();
            missionCreateRecord.setActualEndTime(DateTranslate.simpleDateTimeToString(missionDTO.getStartDate(), "yyyy年MM月dd日  HH:mm:ss"));
            missionCreateRecord.setOperatorName(missionDTO.getCreatorDTO().getUserName());
            StringBuffer content = new StringBuffer("创建了 ");
            content.append("["+missionDTO.getMissionName()+"]");
            content.append("任务");
            missionCreateRecord.setContent(content.toString());
            missionCreateRecord.setLevel(1);
            historyList.add(0,missionCreateRecord);
            
        } catch (BusinessException e) {
            e.printStackTrace();
        }
        if(missionDTO.getActualEndTime() !=null){
            missionEnded= true;
        }
        return historyList;
    }

    public String getContentByJob(JobHandleRecordsDTO job){
        return content.get(job.getMissionTypeKey() + "_" + job.getJobType());
    }

    public Long getMissionId() {
        return missionId;
    }

    public void setMissionId(Long missionId) {
        this.missionId = missionId;
    }

    public MissionDTO getMissionDTO() {
        return missionDTO;
    }

    public void setMissionDTO(MissionDTO missionDTO) {
        this.missionDTO = missionDTO;
    }

    public void setHistoryList(List<JobHandleRecordsDTO> historyList) {
        this.historyList = historyList;
    }

    public boolean isMissionEnded() {
        return missionEnded;
    }

    public void setMissionEnded(boolean missionEnded) {
        this.missionEnded = missionEnded;
    }

}
